package com.woniuxueyuan.Controller;

import com.woniuxueyuan.entity.Book;
import com.woniuxueyuan.service.BookService;
import com.woniuxueyuan.util.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

@RestController
@RequestMapping("/book")
//@CrossOrigin(origins = "*")//此类的方法允许跨域访问，跨域默认不能访问
public class BookController {
    @Resource
    private BookService bookService;
    @GetMapping("/queryAll")
    private ResponseData queryAll(){
        List<Book> books = bookService.queryAll();
//        Iterator<Book> iterator = books.iterator();
//        while (iterator.hasNext()){
//            if (iterator.next().equals("xxx")){
//                iterator.remove();
//            }
//        }  迭代器删除集合元素
        return ResponseData.ok(books);
    }
    @GetMapping("/queryDetail/{id}")
    public ResponseData queryDetail(@PathVariable("id") Integer id){
        Book book = bookService.queryBookById(id);
        return ResponseData.ok(book);
    }
}
